
$(function () {
    $("#jqGrid").Grid({
        url: '../qrCodeMgt/list',
        colModel: [
            // {label: 'id', name: 'id', index: 'id',align:"center", key: true, hidden: true},
            {label: '酒店名称', name: 'hotelName', index: 'hotelName',align:"center", width: 60},
            {label: '酒店地址', name: 'address', index: 'address', width: 60,align:"center",},
            {label: '二维码地址', name: 'codeUrl', index: 'codeUrl', width: 100},
            {
                label: '图片', name: 'codeUrl', index: 'codeUrl',align:"center", width: 60, formatter: function (value) {
                    return transImg(value);
                }
            },
            {
                label: '操作', width: 60, align: 'center', sortable: false, formatter: function (value, col, row) {
                    // console.log(row,11145551);
                    return `<button class="btn btn-outline btn-info btn-xs" onclick="vm.lookDetail(${row.id})"><i class="fa fa-search"></i>&nbsp;二维码预览</button>`
                    // return "<button class='btn btn-outline btn-info btn-xs' onclick='vm.lookDetail( + + )>详情</button>"
                }
            }]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        hotel: {},
        adposition:{},
        ruleValidate: {
            hotelName: [
                {required: true, message: '名称不能为空', trigger: 'blur'}
            ],
            address: [
                {required: true, message: '名称不能为空', trigger: 'blur'}
            ]
        },
        q: {
            param: ''
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.hotel = {width: 200, height: 750};
        },
        update: function (event) {
            var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        saveOrUpdate: function (event) {
            var url = vm.hotel.id == null ? "../qrCodeMgt/addHotel" : "../qrCodeMgt/updateHotel";

            Ajax.request({
                type: "POST",
                url: url,
                contentType: "application/json",
                params: JSON.stringify(vm.hotel),
                successCallback: function () {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
            });


        },
        del: function (event) {
            var ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                Ajax.request({
                    type: "POST",
                    url: "../qrCodeMgt/delete",
                    contentType: "application/json",
                    params: JSON.stringify(ids),
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        getInfo: function (id) {
            Ajax.request({
                url: "../qrCodeMgt/info/" + id,
                async: true,
                successCallback: function (r) {
                    vm.hotel = r.hotelEntity;
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'hotelName': vm.q.param},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },
        lookDetail: function (id) {
            console.log(id,'ass')
            Ajax.request({
                type: "GET",
                url: '../qrCodeMgt/list?limit=9999&page=1&sidx=&order=asc',
                successCallback: function (res) {
                    //console.log(res)
                    var list=res.page.list;
                    var filterList=list.filter(item=>{
                        return item.id==id
                    })
                    window.open(filterList[0].codeUrl);
                }
            });
        }

    }
});